# Contributor: Adam Jensen <adam@acj.sh>
# Maintainer: Adam Jensen <adam@acj.sh>
pkgname=imageflow
pkgver=1.7.0
_rcver=-rc64 # needed until first official release
_commit=c8951261f8d90ea3a445eaa569538d398e19a25e
pkgrel=0
pkgdesc="High-performance image manipulation for web servers"
url="https://github.com/imazen/imageflow"
arch="x86_64" # limited by cargo and SIMD dependency
license="AGPL-3.0-only"
makedepends="bash cargo zip nasm git openssl-dev wget curl libpng-dev dssim"
source="$pkgname-$pkgver$_rcver.tar.gz::https://github.com/imazen/imageflow/archive/v$pkgver$_rcver.tar.gz"
builddir="$srcdir/$pkgname-$pkgver$_rcver"
subpackages="$pkgname-server:_server
	$pkgname-tool:_tool
	"

prepare() {
	# Workaround for environment consistency checks in build
	touch .git

	default_prepare
}

build() {
	# Needed to populate fields displayed at runtime
	version_prefix="v$pkgver$_rcver"
	export GIT_COMMIT="$_commit"
	export GIT_COMMIT_SHORT="${GIT_COMMIT:0:7}"
	export GIT_OPTIONAL_TAG=$version_prefix
	export GIT_DESCRIBE_ALWAYS="$version_prefix"
	export GIT_DESCRIBE_ALWAYS_LONG="$version_prefix-0-alpine"
	export GIT_DESCRIBE_AAL="tags/$version_prefix-0-alpine"
	export GIT_OPTIONAL_BRANCH="n/a"

	cargo build --workspace --release --locked
}

check() {
	cargo test --workspace --release --locked
}

package() {
	install -Dm644 "$builddir/target/release/libimageflow.so" \
		"$pkgdir/usr/lib/libimageflow.so.$pkgver"
	ln -s "libimageflow.so.$pkgver" "$pkgdir/usr/lib/libimageflow.so.${pkgver:0:1}"
	ln -s "libimageflow.so.$pkgver" "$pkgdir/usr/lib/libimageflow.so"
}

_server() {
	pkgdesc="$pkgdesc (HTTP server)"

	install -Dm755 "$builddir/target/release/imageflow_server" \
		"$subpkgdir/usr/bin/imageflow_server"
}

_tool() {
	pkgdesc="$pkgdesc (image resizing tool)"

	install -Dm755 "$builddir/target/release/imageflow_tool" \
		"$subpkgdir/usr/bin/imageflow_tool"
}

sha512sums="192cb6790050b6e0733ffcc2ce204a9840e65c8d2139b8c6ef0207441e3606a43817de9c68d5844054754282daa3b5d594110a115cb6bb793faa44f90b6647fd  imageflow-1.7.0-rc64.tar.gz"
